
package com.hulk.ratel.web.events;


import com.hulk.ratel.common.util.HttpClient4Util;
import com.hulk.ratel.common.util.JsonMapper;

import java.util.Map;

/**
 * @author cmt
 * @E-mail:29572320@qq.com
 * @version Create on: 2017年5月1日 下午10:28:48 Class description
 */

public abstract class AbsEventListener {

	private static final int defaultConnTimeout = 5000;

	private static final int defaultReqTimeout = 20000;

	private static final int increaseConnTimeout = 5000;

	private static final int increaseReqTimeout = 10000;

	private static final int retryCount = 3;

	protected static final JsonMapper json = JsonMapper.JSON_NON_DEFAULT_MAPPER;


	protected void retryCallBack(String url, Map<String, String> m) {
		int i = 0;
		boolean flag = true;
		int connTimeout = defaultConnTimeout;
		int reqTimeout = defaultReqTimeout;

		while ((i < retryCount) & flag) {
			byte[] rb = HttpClient4Util.getInstance().doPost(url, null, m, connTimeout, reqTimeout);
			if (rb != null) {
				flag = false;
				break;
			}
			i++;
			connTimeout = increaseConnTimeout + connTimeout;
			reqTimeout = increaseReqTimeout + reqTimeout;
		}
		
		

	}
	
	void preHandle() {
	}
	
	void excute() {
		preHandle();
		onExcute();
		postHandle();
	}
	void onExcute() {
	}
	
	void postHandle() {
	}

	/**
	 * @param event
	 */
	//public abstract void callBack(Serializable event);

}
